/**
 * @Description:
 * @author 若琳
 * @date 2021/8/11
*/

const {MYSQL}  = require("../../../../../../../../ruoling-common/src/com/ruoling/common/config/mysqlconfig.js");
const Pager_DB = require("../../../../../../../../ruoling-common/src/com/ruoling/common/table/Pager_DB.js");

module.exports = class UserOnlineService{

    static async UserOnlineListService(limit,page,sys_user_login_name,callback){

        try{
            let pagerdb = await new Pager_DB(limit,page).table("rl_sys_user_online")
                .and({"key":"sys_user_login_name","value":sys_user_login_name})
                .order("sys_start_time_stamp","DESC")
                .select();
            callback(null,pagerdb);
            return;
        }catch (e){
            callback(e);
            return;
        }
    };

    /**
     * 用户强退
     * @param sys_user_sessionid
     * @param callback
     * @returns {Promise<void>}
     * @constructor
     */
    static async UserQuitService(sys_user_sessionid,callback){
        let startTrans = null;
        try{
            let connect = await MYSQL().connect();
            startTrans = await connect.startTrans();
            let obj = {
                sql:"update rl_sys_user_online set sys_user_login_state = \"off_line\" where sys_user_sessionid = \""+sys_user_sessionid+"\""
            };
            await startTrans.query(obj.sql);
            await startTrans.commit();
            callback(null,1)
            return ;
        }catch (e){
            await startTrans.rollback();
            callback(e);
            return ;
        }
    }
}